home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Sound / MeterTest / MeterTest.c next >
Encoding:
C/C++ Source or Header  |  1994-07-06  |  3.1 KB  |  85 lines  |  [TEXT/MPS ]

  1. /*****************************************************************************************
  2.      Snippet:            MeterTest.c
  3.      
  4.      Description:        This snippet demonstrates record metering through the use of SPBGetDeviceInfo() 
  5.                         and SPBSetDeviceInfo() using the siLevelMeterOnOff selector. The code calls 
  6.                         SPBSetDeviceInfo() to initially set metering to off, then does a quick sampling of 
  7.                         sound input using SPBGetDeviceInfo(). Metering is then turned on and sampling is 
  8.                         repeated. This is an SIOW application and could be done more elegantly using a
  9.                         graphical representation for sound input levels. But you get the idea. . .
  10.                                                  
  11.      Programmer:            Kevin Mellander
  12.      Organization:        Apple Computer, Inc.
  13.      Department            Developer Technical Support, DTS
  14.      Language/Envir.        MPW Version 3.3.1
  15.      Date Created        7/5/94                          
  16.  
  17.  *****************************************************************************************/
  18. #include <Sound.h>
  19. #include <SoundInput.h>
  20. #include <ToolUtils.h>
  21. #include <Types.h>
  22. #include <stdio.h>
  23.  
  24. struct soundLevelData{
  25.         short meterState;
  26.         short meterSetting;
  27.     } getSoundLevelInfo;
  28.  
  29. void main()
  30. {
  31.     Str255    deviceString;
  32.     OSErr    soundErr = 0;
  33.     long    mySIRefNum;
  34.     short    sampletime = 0;
  35.     short    setSoundMeterState = 1;
  36.     
  37.     getSoundLevelInfo.meterState = 0;
  38.     getSoundLevelInfo.meterSetting = 0;
  39.     
  40.     deviceString[0] = 0;
  41.         
  42.     //Open the sound input device
  43.     soundErr = SPBOpenDevice(deviceString,siWritePermission,&mySIRefNum);
  44.     if (soundErr != noErr)
  45.         DebugStr("\p Failure at call to SPBOpenDevice");
  46.         
  47.     //Set the initial state of the sound input meter to zero just to be sure we start in an "off" state--after all this *is* a test    
  48.     soundErr = SPBSetDeviceInfo(mySIRefNum,siLevelMeterOnOff,(Ptr) &getSoundLevelInfo.meterState);
  49.     if (soundErr != noErr)
  50.         DebugStr("\p Failure at call to SPBSetDeviceInfo set to 0");
  51.  
  52.     //Monitor sound input and make sure everything is really zeroed
  53.     for (sampletime = 0; sampletime<=100; ++sampletime)
  54.     {
  55.         soundErr = SPBGetDeviceInfo(mySIRefNum,siLevelMeterOnOff, (Ptr) &getSoundLevelInfo);
  56.         if (soundErr != noErr)
  57.             DebugStr("\p Failure at call to SPBGetDeviceInfo");
  58.         else
  59.             printf("The GetDeviceInfo meter state is %d and the meter setting is %d\n",getSoundLevelInfo.meterState,getSoundLevelInfo.meterSetting);
  60.     }
  61.     
  62.     //Turn the sound input meter on
  63.     soundErr = SPBSetDeviceInfo(mySIRefNum,siLevelMeterOnOff,(Ptr) &getSoundLevelInfo.meterState);
  64.     if (soundErr != noErr)
  65.         DebugStr("\p Failure at call to SPBSetDeviceInfo set to 1");
  66.     else 
  67.         printf("\nThe call to SPBGetDeviceInfo was successful;\nThe SetDeviceInfo meter state was set to %i\n\n",setSoundMeterState);
  68.         
  69.     
  70.     //Monitor sound input again with meters on 
  71.     for (sampletime = 0; sampletime<=100; ++sampletime)
  72.     {
  73.         soundErr = SPBGetDeviceInfo(mySIRefNum,siLevelMeterOnOff, (Ptr) &getSoundLevelInfo);
  74.         if (soundErr != noErr)
  75.             DebugStr("\p Failure at call to SPBGetDeviceInfo");
  76.         else
  77.             printf("The GetDeviceInfo meter state is %d and the meter setting is %d\n",getSoundLevelInfo.meterState,getSoundLevelInfo.meterSetting);
  78.         
  79.     }
  80.  
  81.     //We're done so close the device
  82.     soundErr = SPBCloseDevice(mySIRefNum);
  83.     if (soundErr != noErr)
  84.         DebugStr("\p Failure at call to SPBCloseDevice");
  85. }